import 'package:flutter/material.dart';

class ZKTabbarViewItem extends StatefulWidget{

  var selectedIdx;
  var idx;
  IconData icon;
  String text;
  final ValueChanged<int> onPress;

  ZKTabbarViewItem({Key key,@required this.selectedIdx,@required this.idx,@required this.icon,@required this.text, this.onPress}) : super(key: key);

  @override
  State<ZKTabbarViewItem> createState() {
    return ZKTabbarViewItemState();
  }
}

class ZKTabbarViewItemState extends State<ZKTabbarViewItem>{

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return GestureDetector(
      onTap: _onTapAction,
      child: Padding(
        padding: EdgeInsets.only(top: 10),
        child: Center(
          heightFactor: 1,
          widthFactor: 1,
          child: SizedBox(
            width: 90,
            height: 44,
            child: Column(
                children: [
                  Icon(widget.icon,color: widget.selectedIdx == widget.idx ? Colors.red : Colors.grey,),
                  Text(widget.text,style: TextStyle(fontSize: 14,color: widget.selectedIdx == widget.idx ? Colors.red : Colors.grey),)
                ]
            ),
          ),
        ),
      )
    );
  }

  void _onTapAction(){
    widget.selectedIdx = widget.idx;
    widget.onPress(widget.idx);
  }
}